package com.tinyspot.concrete.gateway.config;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author Tinyspot
 * @date 2023-01-06 21:08
 */
@Component
@Slf4j
public class PreGlobalFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        HttpHeaders headers = exchange.getRequest().getHeaders();
        MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
        log.info(JSON.toJSONString(queryParams));
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
